package utils

import (
	"webgame/pkg/global"

	"github.com/go-redis/redis"
	"github.com/topfreegames/pitaya/v2/logger"
	"github.com/topfreegames/pitaya/v2/modules"
	"xorm.io/xorm"
)

// var ManagerUtil = &managerUtil{}
var ManagerUtil managerUtil

type managerUtil struct {
}

func (m *managerUtil) GetDbEnginer() (*xorm.Engine, error) {
	// fmt.Println("managerUtil address：", &global.HallApp)
	enginer, err := global.ServerApp.GetModule("databaseStorage")
	if err != nil {
		logger.Log.Errorf("GetDbEnginer failed,error:%s", err.Error())
		return nil, err
	}
	return enginer.(*modules.DatabaseStorage).Enginer, nil
}

func (m *managerUtil) GetRedisClient() (*redis.Client, error) {
	redisStorage, err := global.ServerApp.GetModule("redisStorage")
	if err != nil {
		logger.Log.Errorf("GetDbEnginer failed,error:%s", err.Error())
		return nil, err
	}
	return redisStorage.(*modules.RedisStorage).Client, nil
}
